﻿(function ($) {
    app.modals.CreateOrEditStyleModal = function () {
        var _modalManager;

        var _styleService = abp.services.app.style;

        //$(".maxlength-handler").maxlength({
        //    limitReachedClass: "label label-danger",
        //    alwaysShow: true,
        //    threshold: 5,
        //    placement: 'bottom'
        //});

        var _$styleInformationForm = null;

        this.init = function (modalManager) {
            _modalManager = modalManager;
            _$styleInformationForm = _modalManager.getModal().find("form[name=styleInformationsForm]");

            //渲染select
            $("#cartypeIdEdit").selectpicker();
        }

        this.save = function () {
            if (!_$styleInformationForm.valid()) {
                return;
            }
            //校验通过

            var style = _$styleInformationForm.serializeFormToObject();
            //  console.log(style);

            _modalManager.setBusy(true);

            _styleService.createOrUpdateStyleAsync({
                styleEditDto: style
            }).done(function () {
                //提示信息
                abp.notify.info(app.localize('SavedSuccessfully'));
                //关闭窗体
                _modalManager.close();
                //信息保存成功后调用事件，刷新列表
                abp.event.trigger('app.createOrEditStyleModalSaved');
            }).always(function () {
                _modalManager.setBusy(false);
            });
        }
    }
})(jQuery);